/*
 * @Description: 校验工具
 * @Author: ziwei.ma
 * @Date: 2019-10-14 16:25:58
 * @Last Modified by: ziwei.ma
 * @Last Modified time: 2019-10-22 10:37:53
 */

function verifyUserPhone(userPhone) {
  return new Promise((resolve, reject) => {
    if (!userPhone) {
      let msg = '请输入手机号'
      reject(msg)
    } else if (!/^1[3456789]\d{9}$/.test(userPhone)) {
      let msg = '手机号码格式错误'
      reject(msg)
    } else {
      resolve(userPhone)
    }
  })
}

function verifyVerificationCode(userPhone) {
  return new Promise((resolve, reject) => {
    if (!userPhone) {
      let msg = '请输入验证码'
      reject(msg)
    } else {
      resolve(userPhone)
    }
  })
}

function verifyAgreement(isCheck) {
  return new Promise((resolve, reject) => {
    if (!isCheck) {
      let msg = '请阅读并同意《用户协议》'
      reject(msg)
    } else {
      resolve(isCheck)
    }
  })
}

export { verifyUserPhone, verifyVerificationCode, verifyAgreement }
